package com.xc.stock.domain.basic.repository;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.rp.spring.jpa.GenericJpaRepository;
import com.xc.stock.constant.RoleEnum;
import com.xc.stock.domain.basic.convert.AccountConvert;
import com.xc.stock.domain.basic.convert.IEntityPOConvert;
import com.xc.stock.domain.basic.entity.Account;
import com.xc.stock.infrastructure.db.po.AccountPO;
import com.xc.stock.infrastructure.db.po.QAccountPO;
import com.xc.stock.infrastructure.db.repo.AccountRepo;
import com.xc.stock.utils.SpringUtils;

import lombok.RequiredArgsConstructor;

/**
 * AccountRepository
 *
 * @author xlfd
 * @email xlfd@gmail.com
 * @created 2022/03/25
 */
@Repository
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AccountRepository extends SimplePoConvertEntityRepository<Account, AccountPO, Integer> {
	final AccountRepo repo;
	final AccountConvert convert;
	final static QAccountPO q = QAccountPO.accountPO;
	@Override
	public GenericJpaRepository<AccountPO, Integer> repo() {
		return repo;
	}

	@Override
	public IEntityPOConvert<Account, AccountPO> convert() {
		return convert;
	}

	public static AccountRepository of() {
		return SpringUtils.getBean(AccountRepository.class);
	}

	public List<Account> findByPkId(Integer pId) {
		return findAll(q.pId.eq(pId));
	}
	
	public List<Account> findByDestId(String destId, RoleEnum re) {
		return findAll(q.destId.eq(destId).and(q.role.eq(re.code())));
	}
}
